from cProfile import label

import wx
import random

class MyFrame(wx.Frame):
    NameList = ['mia','tom','jack','tim']
    # 构造方法
    def __init__(self,title="New Application"):
        wx.Frame.__init__(self,None,title=title)
        # 创建面板
        self.pl = wx.Panel(self)
        # 创建静态文本
        self.text = wx.StaticText(self.pl,label="欢迎使用抽奖器",pos=(300,100))
        self.text_name = wx.StaticText(self.pl, label=self.NameList[0], pos=(300, 300))
        # 创建按钮
        ## 开始抽奖和结束抽奖
        self.btn = wx.Button(self.pl,label="开始抽奖",pos=(300,400))
        self.end = wx.Button(self.pl,label="结束抽奖",pos=(400,400))
        # 按钮绑定事件
        self.Bind(wx.EVT_BUTTON,self.onClick,self.btn)
        self.Bind(wx.EVT_BUTTON,self.stop,self.end)

    def onClick(self,event):
        # 设置定时器
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER,self.update_name,self.timer)
        self.timer.Start(100)

    def update_name(self,event):
        index = random.randint(0,len(self.NameList)-1)
        name = self.NameList[index]
        self.text_name.SetLabelText(name)

    def stop(self,event):
        self.timer.Stop()


if __name__ == "__main__":
    # 创建应用程序对象
    app = wx.App()

    # 创建窗口
    frame = MyFrame("抽奖器")
    # 显示窗口
    frame.Show()

    # 窗口一直显示
    app.MainLoop()
